﻿using Halcon二次开发.Controller.数据加载与保存;
using Halcon二次开发.Controller.距离转换工具;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.自定义控件;
using Halcon二次开发.View.卡尺;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.距离转换工具
{
    public partial class DistanceToolForm : Form
    {
        /// <summary>
        /// 工具动作类
        /// </summary>
        public DistanceToolController controller;
        public string nodeName;
        HwindowFlowNodeUrseControl hwindowFlowNode;
        public DistanceToolForm(string name,HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            this.nodeName = name;
            this.hwindowFlowNode = hwindowFlowNode;
            InitializeComponent();
            controller = new DistanceToolController(this,hwindowFlowNode);
        }
        public void GetName(string nodeName)
        {
            this.nodeName = nodeName;
        }
        /// <summary>
        /// 反射调用的方法，请不要修改
        /// </summary>
        /// <param name="path">Json文件的路径</param>
        /// <param name="addres">节点</param>
        public void SetJsonPaths(string path, string addres)
        {
            string paths = path + "\\" + "界面数据\\" + nodeName  + "\\" + addres + "数据.json";
            //调用存储方法
            new LoadData().LoadDatas(paths, this);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                controller.Suan();
            }
            catch(Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
        }

        private void DistanceToolForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                //小运行时获取卡尺工具输出的线段
             controller.HideIntputArrayDistances= (((this.Parent as TabPage).Parent as TabControl).GetControl(0).Tag as PreciseCaliper).controller.HideOutputArrayDistances;
                controller.Suan();
                controller.Run();
            }
            catch (Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
        }
        /// <summary>
        /// 获取像素距离的按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //小运行时获取卡尺工具输出的线段
                controller.HideIntputArrayDistances = (((this.Parent as TabPage).Parent as TabControl).GetControl(0).Tag as PreciseCaliper).controller.HideOutputArrayDistances;
                textBox1.Text = controller.HideIntputArrayDistances[0].ToString("F3");
            }
            catch
            {

            }
        }
    }
}
